import {
	objDeepCopy,
	getDateString
} from "@/assets/js/common.js";
import commonObject from "@/assets/js/xm.js";
let Controller = {
	created() {
		this.init();
	},
	mounted() {

	},
	methods: {
		init() {
			this.getStatusOption(this) //调拨单状态下拉框
			this.getTypeOption(this); //调拨单据类型下拉框
			this.getStoreSelect(this); //仓库 下拉框
			this.getList(this);
		},
		//
		//调拨单类型 下拉框
		getTypeOption(that) {
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'post',
				url: apiTest + '/base/systemDictionary/getListByEntity',
				// url:apiTest+'/base/systemDictionary/getListByEntity',
				data: {
					parentId: 200,
					systemDictionaryTypeId: 22,
				}
			}).then((res) => {
				console.log(res);
				that.Model.getTypeOptionData = [];
				var data = res.data;
				if (data.status == 200) {
					var obj = {};
					var result = data.result;
					for (var i = 0; i < result.length; i++) {
						obj = {
							label: result[i].value,
							value: result[i].key
						}
						that.Model.getTypeOptionData.push(obj)
					}
					that.Model.filterOption.items[1].data = objDeepCopy(that.Model.getTypeOptionData);
				} else {

				}

			});
		},
		//调拨单状态 下拉框
		getStatusOption(that) {
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'post',
				url: apiTest + '/base/systemDictionary/getListByEntity',
				data: {
					systemDictionaryTypeId: 26
				}
			}).then((res) => {
				console.log(res);
				that.Model.getStatusOptionData = [];
				var data = res.data;
				if (data.status == 200) {
					var obj = {};
					var result = data.result;
					for (var i = 0; i < result.length; i++) {
						obj = {
							label: result[i].value,
							value: result[i].key
						}
						that.Model.getStatusOptionData.push(obj);
					}
					that.Model.filterOption.items[3].data = objDeepCopy(that.Model.getStatusOptionData);
				} else {

				}
			});
		},
		//获取 调拨仓库 下拉框
		getStoreSelect(that) {
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'post',
				url: apiTest + '/supplier/supplierFactoryLocation/listNoPage',
				// url:'/api/supplierFactoryLocation/listNoPage',
				data: {}
			}).then((res) => {
				console.log(res);
				that.Model.getStoreOptionData = [];
				var data = res.data;
				if (data.status == 200) {
					var obj = {};
					var result = data.result;
					for (var i = 0; i < result.length; i++) {
						var label = result[i].theNameOfThePlace + '-' + result[i].descriptionOfWarehouseLocation;
						obj = {
							label: label,
							value: result[i].id
						}
						that.Model.getStoreOptionData.push(obj);
					}
					that.Model.filterOption.items[4].data = objDeepCopy(that.Model.getStoreOptionData);
					that.Model.filterOption.items[5].data = objDeepCopy(that.Model.getStoreOptionData);
				} else {

				}

			});
		},
		//获取列表
		getList(that, params, page) {
			params = params || {
				businessType: 100
			};
			page = page || that.Model.page;
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'post',
				url: apiTest + '/supplier/whWarehouse/list',
				// url:'/api/whWarehouse/list',
				data: {
					condition: params,
					pageIndex: page.pageIndex,
					pageSize: page.pageSize,
				}
			}).then((res) => {
				that.Model.tableData = [];
				var data = res.data;
				if (data.status == 200) {
					var obj = {};
					var pagination = commonObject.paginationFunction(data.result);
					that.Model.paginationObject = objDeepCopy(pagination);
					var result = data.result.result;
					if (result) {
						for (var i = 0; i < result.length; i++) {
							obj = objDeepCopy(result[i]);
							if (result[i].typeDict) {
								obj.remarkType = result[i].typeDict.value;
							}
							if (result[i].outWarehouseInfo) {
								obj.outWareLocation = result[i].outWarehouseInfo.theNameOfThePlace + '-' + result[i].outWarehouseInfo.descriptionOfWarehouseLocation;
								obj.intWareLocation = result[i].inWarehouseInfo.theNameOfThePlace + '-' + result[i].inWarehouseInfo.descriptionOfWarehouseLocation;
							}
							if (result[i].statusDict) {
								obj.showStatus = result[i].statusDict.value;
							}
							that.Model.tableData.push(obj)
						}
					}
				} else {

				}
			});
		},
		//卡片切换 回调
		cardEmit(card) {
			var params = {
				businessType: 100,
				status: card.value
			}
			// var searchFromData = this.Model.searchFromData;
			this.Model.filterOption.items[3].value = card.label;
			this.getList(this, params);
		},
		//新建调拨单22,
		newPage() {
			this.$router.push({
				path: 'listAllocationStoreNew',
				query: {

				}
			});
		},
		//详情
		toDetial(row) {
			this.$router.push({
				path: 'listAllocationStoreDetail',
				query: {
					number: row.number
				}
			});
		},
		//点击 强制完结
		forcedEnd(row) {
			let id = row.id;
			var apiTest = this.apiTest;
			var that = this;
			this.$ajax({
				method: 'post',
				url: apiTest + '/supplier/whWarehouse/forceComplete',
				// url:'/api/whWarehouse/forceComplete',
				data: {
					id: id,
					status: 60,
				}
			}).then((res) => {
				var data = res.data;
				if (data.status == 200) {
					var obj = {};
					var result = data.result;
					that.tips(that, 'success', '操作成功');
					that.getList(that)
				} else {
					that.tips(that, 'warning', data.msg);
				}
			});
		},
		//作废请求
		orderObsoleteAjax(that, id) {
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'post',
				url: apiTest + '/supplier/whWarehouse/invalidTransfer',
				// url:'/api/whWarehouse/invalidTransfer',
				data: {
					id: id
				}
			}).then((res) => {
				var data = res.data;
				if (data.status == 200) {
					var obj = {};
					var result = data.result;
					that.tips(that, 'success', '操作成功');
					that.getList(that)
				} else {
					that.tips(that, 'warning', data.msg);
				}
			});
		},
		//点击作废
		orderObsolete(row) {
			var id = row.id;
			this.$confirm('作废该入库单后，则无法再对该单进行操作，是否确定作废?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
			}).then(() => {
				this.orderObsoleteAjax(this, id)
			}).catch(() => {

			});
		},
		//审批请求
		orderApprovalAjax(that, id) {
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'post',
				url: apiTest + '/supplier/whWarehouse/checkTransfer ',
				// url:'/api/whWarehouse/checkTransfer ',
				data: {
					id: id
				}
			}).then((res) => {
				var data = res.data;
				if (data.status == 200) {
					var obj = {};
					var result = data.result;
					that.tips(that, 'success', '操作成功');
					that.getList(that)
				} else {
					that.tips(that, 'warning', data.msg);
				}
			});
		},
		//点击审批
		orderApproval(row) {
			var id = row.id;
			this.$confirm('审批该入库单后，则无法再对该单进行操作，是否确定审批?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
			}).then(() => {
				this.orderApprovalAjax(this, id)
			}).catch(() => {

			});
		},
		selectedHighlight(data) {
			// 如果选中则添加高亮样式
			if (this.Model.TableSelectData.indexOf(data.row) > -1) {
				return {
					"background-color": "#FEF6EE"
				};
				return {}
			}
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		handleSelectionChange(val) {
			this.Model.TableSelectData = val;
		},
		handleCurrentChange(val) {
			var searchFromData = this.Model.searchFromData;
			this.Model.page.pageIndex = val;
			this.getList(this, searchFromData, this.Model.page);
		},
		handleSizeChange(val) {
			var searchFromData = this.Model.searchFromData;
			this.Model.page.pageSize = val;
			this.getList(this, searchFromData, this.Model.page);
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
			this.Model.searchFromData = {
				businessType: 100,
				inWarehouseId: val.inWarehouseId,
				keyword: val.keyword,
				outWarehouseId: val.outWarehouseId,
				status: val.status,
				type: val.type
			}
			if (val.createTime) {
				this.Model.searchFromData.createTimeStart = getDateString(val.createTime[0]);
				this.Model.searchFromData.createTimeEnd = getDateString(val.createTime[1]);
			}
			console.log(this.Model.searchFromData)
		},
		toSearch(val) {
			var searchFromData = this.Model.searchFromData;
			this.getList(this, searchFromData);
		},
		toClear(val) {
			this.Model.searchFromData = {};
			this.Model.filterOption.items[1].data = objDeepCopy(this.Model.getTypeOptionData);
			this.Model.filterOption.items[3].data = objDeepCopy(this.Model.getStatusOptionData);
		},
		toExport(val) {
			console.log(val);
		},
		tips(that, type, message) {
			let duration;
			type == 'success' ? duration = 3000 : duration = 10000;
			that.$message({
				message: message,
				type: type,
				duration: duration
			});
		},
	},
	watch: {
		$route: {
			handler(newValue, oldValue) {
				this.init();
			},
			deep: true
		},

	},
	filters: {
		objFilters: function(value) {

		}
	}
}
export default Controller;
